<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>最长递增子序列</title>
</head>
<body>
  <script>
    function fn(nums) {
      let arr = new Array(nums.length).fill(1);
      for (let i = 0; i < nums.length; i++) {
        // i与i前面的元素比较
        for (let j = 0; j < i; j++) {
          // 找比i小的元素，找到一个，就让当前序列的最长子序列长度加1
          if (nums[i] > nums[j]) {
            arr[i] = Math.max(arr[i], arr[j] + 1);
          }
        }
      }
      // 找出最大的子序列
      return Math.max(...arr);
    }
    console.log(fn([10,9,2,5,3,7,101,18]))
  </script>
</body>
</html>